<?php

/**
 * Abstract storage class
 *
 * @author nam.ngvan@hotmail.com
 */
class Cache
{

	private static $_instances = array();

	/**
	 * @var $name or $config
	 */
	static public function instance($name = null, $config = null)
	{
		if (null == $name)
		{
			$name = 'default';
		}

		if (isset(self::$_instances[$name]))
		{
			return self::$_instances[$name];
		}

		$engine = isset($config['engine']) ? $config['engine'] : null;

		if (!$engine)
		{
			$engine = CACHE_ADAPTER;
		}
		$class = 'Cache_Adapter_' . ucfirst($engine);

		return self::$_instances[$name] = new $class($name, $config);
	}

}
